<?php

/**
 * RabbitCMS
 * 
 * LICENSE
 *
 * This source file is subject to the GNU GENERAL PUBLIC LICENSE Version 2 
 * that is bundled with this package in the file LICENSE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.gnu.org/licenses/gpl-2.0.txt
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@rabbitcms.com so we can send you a copy immediately.
 * 
 * @copyright	Copyright (c) 2009-2010 TIG Corporation (http://www.tig.vn)
 * @license		http://www.gnu.org/licenses/gpl-2.0.txt GNU GENERAL PUBLIC LICENSE Version 2
 * @version 	$Id: Resource.php 5028 2010-08-28 16:44:55Z huuphuoc $
 * @since		2.0.5
 */
class Core_Models_Resource extends Rabbit_Db_Table_Abstract implements Core_Models_Interfaces_Resource {

    protected $_name = 'core_resource';

    public function convert($entity) {
        return new Core_Models_Entities_Resource($entity);
    }

    public function getResources($module = null) {
        $select = $this->select();
        if ($module) {
            $select = $select->where('module_name = ?', mysql_real_escape_string($module));
        }

        return $this->fetchAll($select);
    }

    public function getById($id) {
        return $this->find($id)->current();
    }

    public function add($params) {
        $resource = $this->createRow($params);
        if ($resource->save())
            return $resource->id;
        else
            return false;
    }

    public function delete($id) {
        return parent::delete('id = ' . $id);
    }

}
